'''
Created on 14.12.2012

@author: fre
'''
from game import GameLogic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.Heuristic import \
    Heuristic

class WinningHeuristic(Heuristic):
    '''
    classdocs
    '''
    def __init__(self, weighting,):
        Heuristic.__init__(self, weighting)
        self.cont = True

#    def heuristicComplex(self, field, action, color, nextColor, depth):
#        if not self.cont:
#            self.cont = True
#            return 0
#        self.cont = False
#        # try to build rows of 5 or more points
#        bestPair = GameLogic.getMaxLen(field, color, 0, GameLogic.WIN_LENGTH)
#        if bestPair is None:
#            return 0
#        maxLen, direction, position  = bestPair
#        if maxLen >= GameLogic.WIN_LENGTH:
#            return 2
#        if maxLen == GameLogic.WIN_LENGTH-1:
#            exp1 = GameLogic.numExpendableInDirection(field, position, direction, color)
#            direction = GameLogic.switchDirection(direction)
#            exp2 = GameLogic.numExpendableInDirection(field, position, direction, color)
#            if exp1 > 0 and exp2 > 0:
#                return 1
#        if maxLen == GameLogic.WIN_LENGTH-2:
#            exp1 = GameLogic.numExpendableInDirection(field, position, direction, color)
#            direction = GameLogic.switchDirection(direction)
#            exp2 = GameLogic.numExpendableInDirection(field, position, direction, color)
#            if exp1 > 0 and exp2 > 0:
#                return (1./self.weighting)*5
#        op = -self.heuristic(field, action, -color, nextColor, depth)
#        return op/2.0
    
    def heuristic(self, field, action, color, nextColor, depth):
        return GameLogic.getJustMaxLen(field, action, GameLogic.WIN_LENGTH) >= GameLogic.WIN_LENGTH